# 第一阶段：构建阶段
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/maven:3.9.9-eclipse-temurin-21-alpine AS builder

# 设置工作目录
WORKDIR /build

# 只复制 admin3-server 目录的内容
COPY pom.xml .
COPY src src/

# 配置 Maven 镜像源
RUN mkdir -p /usr/share/maven/conf/ && \
    sed -i '/<mirrors>/a\    <mirror>\n      <id>aliyun-public</id>\n      <mirrorOf>*</mirrorOf>\n      <name>Aliyun Public</name>\n      <url>https://maven.aliyun.com/nexus/content/groups/public/</url>\n    </mirror>' /usr/share/maven/conf/settings.xml

# 执行构建
RUN mvn clean package -DskipTests

# 第二阶段：运行阶段
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/eclipse-temurin:21-jdk-alpine

# 设置工作目录
WORKDIR /app

# 从构建阶段复制 jar 文件
COPY --from=builder /build/target/admin3-server-*-SNAPSHOT.jar admin3-server.jar

# 设置 JVM 参数
ENV JAVA_OPTS="-Xms256m -Xmx512m"

# 暴露端口
EXPOSE 8080

# 启动命令，指定配置文件位置
ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar admin3-server.jar --spring.config.location=file:/app/application.yml"]